package com.ww.juc.jd.async.basic;

import java.util.concurrent.ExecutionException;

import com.jd.platform.async.executor.Async;
import com.jd.platform.async.wrapper.WorkerWrapper;

import cn.hutool.core.date.SystemClock;

public class TestDemo2 {

	public static void main(String[] args) throws ExecutionException, InterruptedException {
		ParWorker w = new ParWorker();
		ParWorker1 w1 = new ParWorker1();
		ParWorker2 w2 = new ParWorker2();
		ParWorker3 w3 = new ParWorker3();

		WorkerWrapper<String, String> workerWrapper3 = new WorkerWrapper.Builder<String, String>()
				.worker(w3)
				.callback(w3)
				.param("3")
				.build();

		WorkerWrapper<String, String> workerWrapper2 = new WorkerWrapper.Builder<String, String>()
				.worker(w2)
				.callback(w2)
				.param("2")
				.next(workerWrapper3)
				.build();

		WorkerWrapper<String, String> workerWrapper1 = new WorkerWrapper.Builder<String, String>()
				.worker(w1)
				.callback(w1)
				.param("1")
				.next(workerWrapper3)
				.build();

		WorkerWrapper<String, String> workerWrapper = new WorkerWrapper.Builder<String, String>()
				.worker(w)
				.callback(w)
				.param("0")
				.next(workerWrapper1, workerWrapper2)
				.build();

		long now = SystemClock.now();

		Async.beginWork(3100, workerWrapper);

		System.out.println("耗时：" + (SystemClock.now() - now) / 1000 + "秒");

		Async.shutDown();
	}
}
